Modula-2

Contents|Index|Previous|Next
Modula-2

The following documentation describes specific Modula-2 extensions for GDB.

- Operators
- Built-in functions and procedures
- Constants
- Modula-2 defaults
- Deviations from standard Modula-2
- Modula-2 type and range checks
- The scope operators, `::` and `.`
- GDB and Modula-2

The extensions made to GDB to support Modula-2 only support output from the GNU Modula-2 compiler (currently in development). Other Modula-2 compilers are not currently supported, and attempting to debug executables produced by them is most likely to give an error as GDB reads in the executables symbol table.

Operators

Operators must be defined on values of specific types. For instance, + is defined on numbers and not on structures. Operators are often defined on groups of types. For the purposes of Modula-2, the following definitions hold.

- Integral types consist of INTEGER, CARDINAL, and their subranges.
- Character types consist of CHAR and its subranges.
- Floating-point types consist of REAL.
- Pointer types consist of anything declared as POINTER TO type.
- Scalar types consist of all of the previous types.
- Set types consist of SET and BITSET types.
- Boolean types consist of BOOLEAN.

The following operators are supported, and appear in order of increasing precedence.

,

Function argument or array index separator.

:=

Assignment. The value of var :=value is value.

<, >

Less than, greater than on integral, floating-point, or enumerated types.

<=, >=

Less than, greater than, less than or equal to, greater than or equal to on integral, floating-point and enumerated types, or set inclusion on set types. Same precedence as <.

=, <>, #

Equality and two ways of expressing inequality, valid on scalar types. Same precedence as <. In GDB scripts, only <> is available for inequality, since # conflicts with the script comment character.

IN

Set membership. Defined on set types and the types of their members. Same precedence as <.

OR

Boolean disjunction. Defined on boolean types.

AND, &

Boolean conjuction. Defined on boolean types.

@

The GDB artificial array operator (see Expressions).

+, -

Addition and subtraction on integral and floating-point types, or union and difference on set types.

*

Multiplication on integral and floating-point types, or set intersection on set types.

/

Division on floating-point types, or symmetric set difference on set types. Same precedence as *.

DIV, MOD

Integer division and remainder. Defined on integral types. Same precedence as *.

-

Negative. Defined on INTEGER and REAL data.

Pointer dereferencing. Defined on pointer types.

NOT

Boolean negation. Defined on boolean types. Same precedence as .

.

RECORD field selector. Defined on RECORD data. Same precedence as .

[]

Array indexing. Defined on ARRAY data. Same precedence as .

()

Procedure argument list. Defined on PROCEDURE objects. Same precedence as .

:: and .

GDB and Modula-2 scope operators.

Warning:
Sets and their operations are not yet supported, so GDB treats the use of the operator, IN, or the use of operators, +, -, *, /, =,<>, #, <=, and >= , on sets as an error.

Built-in functions and procedures

Modula-2 also makes available several built-in procedures and functions. In describing these, the following meta-variables are used:

a

Represents an ARRAY variable.

c

Represents a CHAR constant or variable.

i

Represents a variable or constant of integral type.

m

Represents an identifier that belongs to a set. Generally used in the same function with the metavariable, s. The type of s should be SET OF mtype (where mtype is the type of m).

n

Represents a variable or constant of integral or floating-point type.

r

Represents a variable or constant of floating-point type.

t

Represents a type.

v

Represents a variable.

x

Represents a variable or constant of one of many types. See the explanation of the function for details.
All Modula-2 built-in procedures also return a result, described in the following discussion.

- ABS(n)
Returns the absolute value of n.

- CAP(c)
If c is a lower case letter, it returns its upper case equivalent, otherwise it returns its argument

- CHR(i)
Returns the character whose ordinal value is i.

- DEC(v)
Decrements the value in the variable, v. Returns the new value.

- DEC(v, i)
Decrements the value in the variable, v, by i. Returns the new value.

- EXCL(m, s)
Removes the element, m, from the set, s. Returns the new set.

- FLOAT(i)
Returns the floating point equivalent of the integer, i.

- HIGH(a)
Returns the index of the last member of a.

- INC(v)
Increments the value in the variable, v. Returns the new value.

- INC(v, i)
Increments the value in the variable v by i. Returns the new value.

- INCL(m, s)
Adds the element m to the set s if it is not already there. Returns the new set.

- MAX(t)
Returns the maximum value of the type t.

- MIN(t)
Returns the minimum value of the type t.

- ODD(i)
Returns boolean TRUE if i is an odd number.

- ORD(x)
Returns the ordinal value of its argument. For example, the ordinal value of a character is its ASCII value (on machines supporting the ASCII character set). x must be of an ordered type, which include integral, character and enumerated types.

- SIZE(x)
Returns the size of its argument. x can be a variable or a type.

- TRUNC(r)
Returns the integral part of r.

- VAL(t, i)
Returns the member of the type t whose ordinal value is i.

Warning:
Sets and their operations are not yet supported, so GDB treats the use of procedures, INCL and EXCL, as an error.

Constants

GDB allows you to express the constants of Modula-2 in the following ways:

- Integer constants are simply a sequence of digits. When used in an expression, a constant is interpreted to be type-compatible with the rest of the expression. Hexadecimal integers are specified by a trailing H, and octal integers by a trailing B.
- Floating point constants appear as a sequence of digits, followed by a decimal point and another sequence of digits. An optional exponent can then be specified, in the form E[+|-]nnn, where [+|-]nnn is the desired exponent. All of the digits of the floating point constant must be valid decimal (base 10) digits.
- Character constants consist of a single character enclosed by a pair of like quotes, either single () or double (). They may also be expressed by their ordinal value (their ASCII value, usually) followed by a C.
- String constants consist of a sequence of characters enclosed by a pair of like quotes, either single () or double (). Escape sequences in the style of C are also allowed. See C and C++ constants for a brief explanation of escape sequences.
- Enumerated constants consist of an enumerated identifier.
- Boolean constants consist of the identifiers TRUE and FALSE.
- Pointer constants consist of integral values only.
- Set constants are not yet supported.

Modula-2 defaults

If type and range checking are set automatically by GDB, they both default to on whenever the working language changes to Modula-2. This happens regardless of whether you, or GDB, selected the working language.

If you allow GDB to set the language automatically, then entering code compiled from a file whose name ends with .mod sets the working language to Modula-2. See Setting the working language for further details.

Deviations from standard Modula-2

A few changes have been made to make Modula-2 programs easier to debug. This is done primarily via loosening its type strictness.

- Unlike in standard Modula-2, pointer constants can be formed by integers. This allows you to modify pointer variables during debugging. (In standard Modula-2, the actual address contained in a pointer variable is hidden from you; it can only be modified through direct assignment to another pointer variable or expression that returned a pointer.)
- C escape sequences can be used in strings and characters to represent non-printable characters. GDB prints out strings with these escape sequences embedded. Single non-printable characters are printed using the CHR(nnn) format.
- The assignment operator (:=) returns the value of its right-hand argument.
- All built-in procedures both modify and return their argument.

Modula-2 type and range checks

Warning:
In this release, GDB does not yet perform type or range checking.

GDB considers two Modula-2 variables type equivalent if they have the following criteria.

- They are of types that have been declared equivalent via a TYPE t1 = t2 statement
- They have been declared on the same line.

Note:
This is true of the GNU Modula-2 compiler, but it may not be true of other compilers.)

As long as type checking is enabled, any attempt to combine variables whose types are not equivalent is an error. Range checking is done on all mathematical operations, assignment, array index bounds, and all built-in functions and procedures.

The scope operators, :: and .

There are a few subtle differences between the Modula-2 scope operator (.) and the GDB scope operator (::). The two have similar syntax:

module . id
scope :: id

scope is the name of a module or a procedure, module, the name of a module, and id is any declared identifier within your program, except another module. Using the :: operator makes GDB search the scope specified by scope for the identifier id. If it is not found in the specified scope, then GDB searches all scopes enclosing the one specified by scope.

Using the . operator makes GDB search the current scope for the identifier specified by id that was imported from the definition module specified by module. With this operator, it is an error if the identifier, id, was not imported from definition module, module, or if id is not an identifier in module.

GDB and Modula-2

Some GDB commands have little use when debugging Modula-2 programs. Five subcommands of set print and show print apply specifically to C and C++: vtbl, demangle, asm-demangle, object, and union. The first four apply to C++, and the last to the C union type, which has no direct analogue in Modula-2.

The @ operator (see Expressions), while available while using any language, is not useful with Modula-2. Its intent is to aid the debugging of dynamic arrays, which cannot be created in Modula-2 as they can in C or C++. However, because an address can be specified by an integral constant, the construct {type}adrexp is still useful. (see Expressions)

In GDB scripts, the Modula-2 inequality operator # is interpreted as the beginning of a comment. Use <> instead.

Top|Contents|Index|Previous|Next